package cn.paidaxin.controller;

import cn.paidaxin.listener.XinnuoClockListener;
import cn.paidaxin.task.SeleniumTask;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Pai dx
 * @Description
 * @date 2021-08-20 14:28
 **/
@Api("测试Contro")
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private XinnuoClockListener xinnuoClockListener;

    @Autowired
    private SeleniumTask seleniumTask;

    @Autowired
    private RedisTemplate<String,String> redisTemplate;

    @GetMapping("/onClick")
    public String onClick(){
        try {
            seleniumTask.zsxnAutoLoginTask();
            return "success";
        } catch(Exception e) {
            e.printStackTrace();
            return "fail";
        }
    }

    @GetMapping("/mqOnClick")
    public String mqOnClick() {
        try {
            String msg = "{\"username\":\"SZW210518\",\"password\":\"Xx258147\",\"clockType\":\"xb\"}";

            xinnuoClockListener.xinnuoClockListener(msg);
            return "success";
        } catch(Exception e) {
            e.printStackTrace();
            return "fail";
        }
    }

    @GetMapping("/getMsg")
    public String msg(){
        return redisTemplate.opsForValue().get("XINNUO:CLOCKIN:USERNAME:SZW210518");
    }
}
